/*
 *  Class name: ImageViewerController.java
 *  Version: 1.0
 *  Date: 20.6.2014
 */

package cz.morosystems.personwebmanager.presentationlayer.controllers;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 * @author Michal Ďuriš
 */
@Controller
public class ImageViewerController {
    
    @Value("#{configProperties['imageViewer.fileDirectory']}")
    private String fileDirectory;

    public ImageViewerController() {
    }
    
    @RequestMapping("/imageViewer/{fileName:.+}")
    @ResponseBody
    public byte[] getImage(@PathVariable String fileName) throws IOException {
        
      return Files.readAllBytes(new File(fileDirectory + fileName).toPath());
    }
}
